package com.example.demo.common;



import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

//统一异常类处理,使用 @ControllerAdvice + @ExceptionHandler实现
@ControllerAdvice
@ResponseBody
public class ErrorAdvice {
    @ExceptionHandler(Exception.class)
    public Object Advice(Exception e) {
        return Result.fail(-1,e.getMessage()); //异常的时候执行Result类的fail方法
    }
}
